<?php

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
$smarty->assign('app','report');

$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$id = intval($_REQUEST['id']);

$cache_id = sprintf('%X', crc32($id . '-' . $page));
if (!$smarty->is_cached('category.dwt', $cache_id)) {
    $position = assign_ur_here(0, "检测报告");
    $smarty->assign('page_title', $position['title']); // 页面标题
    $smarty->assign('ur_here', $position['ur_here']);
    assign_template();
    $smarty->assign('helps', get_shop_help());
    $smarty->assign('categories', get_categories_tree()); // 分类树

    if ($id == 0) {
        $sql = "select * from " . $ecs->table("article_cat") . " where parent_id=200";
        $smarty->assign('sub_cate', $db->getAll($sql)); // 分类树    
    }
    $where = " where 1 ";
    if ($id == 0) {
        $where.=" and cat_id in(select cat_id from " . $ecs->table('article_cat') . " where parent_id=200)";
    }
    else {
        $where.=" and cat_id=$id";
    }
    $sql = "select count(*) from " . $ecs->table('article') . $where;
    $record_count = $db->getOne($sql);
    $pager = get_pager('report.php', array('id' => $id), $record_count, $page, 12);
    $smarty->assign('pager',$pager);
    //print_r($pager);exit;
    $sql = "select * from " . $ecs->table('article') . $where." limit $pager[start],$pager[size]";
    $smarty->assign('report_list',$db->getAll($sql));
}
$smarty->display("report.dwt");